﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication4.Models;

namespace WebApplication4.Controllers
{
    public class DefaultController : Controller
    {
        private fashionshoppingDBEntities _context;
        public DefaultController()
        {
            _context = new fashionshoppingDBEntities();
        }
        // GET: Default

        public ActionResult Index()
        {
            var user = _context.Users.ToList();

            return View(user);
        }

        public ActionResult Login()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Login(Sysuser users)
        {
            using (_context)
            {
                if (ModelState.IsValid)
                {
                    var login = _context.Sysusers.FirstOrDefault(x => x.username == users.username && x.pwd == users.pwd);
                    if (login==null)
                    {
                        ModelState.AddModelError("", "用户名或密码错误");

                    }
                    else
                    {
                        return RedirectToAction("Index");
                    }
                }
            }
            return View();
        }
    }
}